package com.scholar.goods.controller;

import com.scholar.shop.common.CommonRes;
import com.scholar.shop.seller.category.api.GoodsCategoryApi;
import com.scholar.shop.seller.category.domain.GoodsBrandOpenVO;
import com.scholar.shop.seller.category.domain.GoodsCategoryOpenVO;
import com.scholar.shop.seller.category.domain.GoodsParamsGroupOpenVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 店铺商品分类相关操作
 * @author kimmy
 **/
@RestController
@RequestMapping("/seller/goods/category")
public class GoodsCategoryController {

    @Autowired
    private GoodsCategoryApi goodsCategoryApi;

    /**
     * 获取父类目
     * @param categoryId 类目id
     * @return 结果集
     */
    @GetMapping(value = "/{categoryId}/children")
    public CommonRes<List<GoodsCategoryOpenVO>> list(@PathVariable("categoryId") Integer categoryId) {
        return goodsCategoryApi.list(categoryId);
    }

    /**
     * 获取该商家关联的所有子类目
     * @return 类目结果集
     */
    @GetMapping(value = "/seller/children")
    public CommonRes<List<GoodsCategoryOpenVO>> listSeller() {
        return goodsCategoryApi.listChildren();
    }

    /**
     * 获取所选分类关联的参数信息
     * @param categoryId 类目id
     * @param goodsId 商品id
     * @return 结果集
     */
    @GetMapping(value = "/{categoryId}/{goodsId}/params")
    public CommonRes<List<GoodsParamsGroupOpenVO>> queryParams(@PathVariable("categoryId") Integer categoryId,
           @PathVariable("goodsId") Integer goodsId) {
        return goodsCategoryApi.queryParams(categoryId, goodsId);
    }

    /**
     * 获取所选商品分类关联的属性分组及属性名和属性值
     * @param categoryId 类目id
     * @return 结果集
     */
    @GetMapping(value = "/{categoryId}/params")
    public CommonRes<List<GoodsParamsGroupOpenVO>> queryParams(@PathVariable("categoryId") Integer categoryId) {
        return goodsCategoryApi.queryParams(categoryId);
    }

    /**
     * 获取所选分类关联的品牌信息
     * @param categoryId 类目id
     * @return 结果集
     */
    @GetMapping(value = "/{categoryId}/brands")
    public CommonRes<List<GoodsBrandOpenVO>> queryBrands(@PathVariable("categoryId") Integer categoryId) {
        return goodsCategoryApi.queryBrands(categoryId);
    }

}
